package com.us.usws.biz;

import net.iwsh.core.common.GlobalConfig;

import org.apache.commons.lang3.StringUtils;

public class WSResourceURIReplacer extends ResourceURIReplacer {

	/**
	 * get my channel url
	 * @param focusChannelUid
	 * @return
	 */
	public static String getMyChannelURL(String focusedChannelUid) {
		//${Host/URL}/api/ebox/my_channels.json?focus_channel_id={focusedChannelUid}
		String ret = GlobalConfig.getString("WSLinkURLs/MyChannel");
		ret = StringUtils.replace(ret, "{focusedChannelUid}", focusedChannelUid);
		return ret;
	}

	/**
	 * get video info url
	 * @param videoUid
	 * @return
	 */
	public static String getVideoInfoURL(String videoUid) {
		//${Host/URL}/api/ebox/movies/{videoUid}.json
		String ret = GlobalConfig.getString("WSLinkURLs/VideoInfo");
		ret = StringUtils.replace(ret, "{videoUid}", videoUid);
		return ret;
	}

	/**
	 * get sub channels url
	 * @param channelUid
	 * @param focusedChannelUid
	 * @return
	 */
	public static String getSubChannelsURL(String channelUid, String focusedChannelUid) {
		//${Host/URL}/api/ebox/channels/{channelUid}/sub_channels.json?focus_channel_id={focusedChannelUid}
		String ret = GlobalConfig.getString("WSLinkURLs/SubChannels");
		ret = StringUtils.replace(ret, "{channelUid}", channelUid);
		ret = StringUtils.replace(ret, "{focusedChannelUid}", focusedChannelUid);
		return ret;
	}

	/**
	 * get channel videos list url
	 * @param channelUid
	 * @return
	 */
	public static String getChannelVideosListURL(String channelUid) {
		//${Host/URL}/api/ebox/channels/{channelUid}/movies.json
		String ret = GlobalConfig.getString("WSLinkURLs/ChannelVideosList");
		ret = StringUtils.replace(ret, "{channelUid}", channelUid);
		return ret;
	}

	/**
	 * get channel video list url with pageno
	 * @param channelUid
	 * @param pageNo
	 * @return
	 */
	public static String getChannelVideosListURLWithPageNo(String channelUid, int pageNo, int pageCnt) {
		//${Host/URL}/api/ebox/channels/{channelUid}/movies.json?page={pageNo}
		int realPageNo;
		if (pageNo < 1) {
			realPageNo = 1;
		} else if (pageNo > pageCnt) {
			realPageNo = pageCnt;
		} else {
			realPageNo = pageNo;
		}

		String ret = GlobalConfig.getString("WSLinkURLs/ChannelVideosListWithPageNo");
		ret = StringUtils.replace(ret, "{channelUid}", channelUid);
		ret = StringUtils.replace(ret, "{pageNo}", Integer.toString(realPageNo));
		return ret;
	}

	/**
	 * channel meetings
	 * @param channelUid
	 * @param pageNo
	 * @param pageCnt
	 * @return
	 */
	public static String getChannelMeetingsURLWithPageNo(String channelUid, int pageNo, int pageCnt) {
		int realPageNo;
		if (pageNo < 1) {
			realPageNo = 1;
		} else if (pageNo > pageCnt) {
			realPageNo = pageCnt;
		} else {
			realPageNo = pageNo;
		}

		String ret = GlobalConfig.getString("WSLinkURLs/ChannelMeetingsWithPageNo");
		ret = StringUtils.replace(ret, "{channelUid}", channelUid);
		ret = StringUtils.replace(ret, "{pageNo}", Integer.toString(realPageNo));
		return ret;
	}

	public static String getChannelMeetingsURL(String channelUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/ChannelMeetings");
		ret = StringUtils.replace(ret, "{channelUid}", channelUid);
		return ret;
	}

	/**
	 * get my meetings
	 * @param userUid
	 * @param pageNo
	 * @param pageCnt
	 * @return
	 */
	public static String getMyMeetingsURLWithPageNo(String userUid, int pageNo, int pageCnt) {
		int realPageNo;
		if (pageNo < 1) {
			realPageNo = 1;
		} else if (pageNo > pageCnt) {
			realPageNo = pageCnt;
		} else {
			realPageNo = pageNo;
		}

		String ret = GlobalConfig.getString("WSLinkURLs/MyMeetingsWithPageNo");
		ret = StringUtils.replace(ret, "{userUid}", userUid);
		ret = StringUtils.replace(ret, "{pageNo}", Integer.toString(realPageNo));
		return ret;
	}

	/**
	 * get category video list url
	 * @param videoCatUid
	 * @return
	 */
	public static String getCategoryVideoListURL(String videoCatUid) {
		//${Host/URL}/api/ebox/categories/{categoryId}/movies.json

		String ret = GlobalConfig.getString("WSLinkURLs/CategoryVideoList");
		ret = StringUtils.replace(ret, "{videoCatUid}", videoCatUid);
		return ret;
	}

	/**
	 * get user profile url
	 * @param userUid
	 * @return
	 */
	public static String getUserUrl(String userUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/UserProfile");
		ret = StringUtils.replace(ret, "{userUid}", userUid);
		return ret;
	}

	/**
	 * get video attendee url
	 * @param videoUid
	 * @return
	 */
	public static String getVideoAttendeeUrl(String videoUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/VideoAttendeeApply");
		ret = StringUtils.replace(ret, "{videoUid}", videoUid);
		return ret;
	}

	/**
	 * get video vote list url
	 * @param videoUid
	 * @return
	 */
	public static String getVideoCommentUrl(String videoUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/VideoCommentList");
		ret = StringUtils.replace(ret, "{videoUid}", videoUid);
		return ret;
	}

	/**
	 * get video comment url with pagination
	 * @param videoUid
	 * @param pageNo
	 * @param pageCnt
	 * @return
	 */
	public static String getVideoCommentListURLWithPageNo(String videoUid, int pageNo, int pageCnt) {
		//${Host/URL}/api/ebox/channels/{channelUid}/movies.json?page={pageNo}
		int realPageNo;
		if (pageNo < 1) {
			realPageNo = 1;
		} else if (pageNo > pageCnt) {
			realPageNo = pageCnt;
		} else {
			realPageNo = pageNo;
		}

		String ret = GlobalConfig.getString("WSLinkURLs/VideoCommentListWithPageNo");
		ret = StringUtils.replace(ret, "{videoUid}", videoUid);
		ret = StringUtils.replace(ret, "{pageNo}", Integer.toString(realPageNo));
		return ret;
	}

	/**
	 * get meeting info
	 * @param meetingUid
	 * @return
	 */
	public static String getMeetingInfoUrl(String meetingUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/MeetingInfo");
		ret = StringUtils.replace(ret, "{meetingUid}", meetingUid);
		return ret;
	}

	public static String getThemeInfoURL(String themeUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/ThemeInfo");
		ret = StringUtils.replace(ret, "{themeUid}", themeUid);
		return ret;
	}

	public static String getLevel2StudentChannelURL(String themeUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/ThemeInfo");
		ret = StringUtils.replace(ret, "{themeUid}", themeUid);
		return ret;
	}

	public static String getStudentSubChannelsURL(String channelUid) {
		String ret = GlobalConfig.getString("WSLinkURLs/Level2StudentSubChannelsURL");
		ret = StringUtils.replace(ret, "{channelUid}", channelUid);
		return ret;
	}

}
